package vip.xiaonuo.modular.xyethniccate.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.core.annotion.version.ApiVersionSwagger;
import vip.xiaonuo.modular.xyethniccate.entity.XyEthnicCate;
import vip.xiaonuo.modular.xyethniccate.service.XyEthnicCateService;
import vip.xiaonuo.sys.core.msg.Result;

import java.util.Collections;
import java.util.List;

import static vip.xiaonuo.modular.xyethnic.constant.EthnicConstant.RelationshipConstant.mother;
import static vip.xiaonuo.modular.xyethnic.constant.EthnicConstant.RelationshipConstant.spouse;
import static vip.xiaonuo.sys.core.msg.ResultUtils.success;

@RestController
@Api(tags = "内部族员关系apis")
@ApiVersionSwagger
@RequestMapping("/ethnicCate")
public class ApiEthnicCateController {

    @Autowired
    private XyEthnicCateService ethnicCateService;


    @GetMapping("/findLevelJoinList/{typeFlag}")
    @ApiOperation(value = "查询关系对应的下拉选择框",notes = "1=(母,妻),2=(兄妹),3=(儿排行),4=(女排行)")
    public Result<List<XyEthnicCate>> findLevelJoinList(@PathVariable Integer typeFlag){
        return success(ethnicCateService.list(Wrappers.<XyEthnicCate>lambdaQuery().eq(XyEthnicCate::getTypeFlag,typeFlag)));
    }

    @GetMapping("/findLevelJoinListByShip/{relationship}/{type}/{sex}")
    @ApiOperation(value = "根据relationship 决断是否是选择框",notes = "type =1 关系；2=排行;sex = 1男,2女")
    public Result<List<XyEthnicCate>> findLevelJoinListByShip(@PathVariable String relationship,@PathVariable Integer type,@PathVariable Integer sex){
        List<XyEthnicCate> objects = Collections.emptyList();
        // 有意思了.
        if (mother.equals(relationship) || spouse.equals(relationship)){
            // 如果是母亲的话 并且是排行 输入框
            if (type.equals(2))
                return success(objects);

            // 那就是关系
            return success(ethnicCateService.list(Wrappers.<XyEthnicCate>lambdaQuery().eq(XyEthnicCate::getTypeFlag,1)));
        }else{
            // 全部都是选择框
            if (type.equals(1)){
                // 如果是关系的话
                return success(ethnicCateService.list(Wrappers.<XyEthnicCate>lambdaQuery().eq(XyEthnicCate::getTypeFlag,2)));
            }
            // 如果是排行的话 需要性别了
            if (sex.equals(1))
                return success(ethnicCateService.list(Wrappers.<XyEthnicCate>lambdaQuery().eq(XyEthnicCate::getTypeFlag,3)));
            else if (sex.equals(2))
                return success(ethnicCateService.list(Wrappers.<XyEthnicCate>lambdaQuery().eq(XyEthnicCate::getTypeFlag,4)));

        }
        return success(objects);
    }
}
